package com.cytech.cookielearn.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
public class SessionController {
    @GetMapping("/getSession")
    public String setSession(HttpServletRequest request, HttpServletResponse response) {
        // 获取session对象
        HttpSession session = request.getSession();

        //session失效
//        session.invalidate();

        // 解绑某一个属性
        session.removeAttribute("username");


        // 向session中域中写入属性
        session.setAttribute("username", "haojq");

        return "set session";
    }
}
